import { creepRuleEnum } from "../../enum"
import { checkCreepSelf } from "../../tools/memoryData"

const creepManager = {
    init: function () {

    },
    run: function () {
        if (!Memory.creeps) Memory.creeps = {}
        Object.keys(Memory.creeps).map(creepName => {
            if (!checkCreepSelf(creepName)) return          // TODO:自检流程,不应该每tick都进行，后续优化
            let creep = Game.creeps[creepName]
            if (creep.spawning) return                      // 孵化中
            if (creep.memory.state.sleep) {                 // 休眠状态
                ruleCreepSleep(creep)
                return
            }
            // console.log(`准备开始执行${creep.name}的${creep.name + JSON.stringify(creep.memory.state.isWorking ? "工作" : "准备")}逻辑？`);
            creepRuleEnum[creep.memory.rule].run(creep)     // 执行creep角色逻辑
        })
    }
}

function ruleCreepSleep(creep) {
    creep.say('休眠中')
}

export default creepManager